package com.xxxx.server.controller;


import com.xxxx.server.pojo.*;
import com.xxxx.server.service.ICollegeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * 学院表 前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2022-04-23
 */
@RestController
@RequestMapping("/col/college")
public class CollegeController {

    @Autowired
    private ICollegeService collegeService;

    @ApiOperation(value = "获取所有学院信息")
    @GetMapping("/")
    public List<College> getAllCollege(){
        return collegeService.list();
    }


    @ApiOperation(value = "添加学院信息")
    @PostMapping("/")
    public RespBean addCollege(@RequestBody College college){
        if (collegeService.save(college)){
            return RespBean.success("添加成功！");
        }
        return RespBean.error("添加失败!");
    }

    @ApiOperation(value = "更新学院信息")
    @PutMapping("/")
    public RespBean updateCollege(@RequestBody College college){
        if (collegeService.updateById(college)){
            return RespBean.success("更新成功！");
        }
        return RespBean.error("更新失败！");
    }

    @ApiOperation(value = "删除学院信息")
    @DeleteMapping("/{id}")
    public RespBean deleteCollege(@PathVariable Integer id){
        if (collegeService.removeById(id)){
            return RespBean.success("删除成功!");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation(value = "批量删除学院信息")
    @DeleteMapping("/")
    public RespBean deleteCollegeByIds(Integer[] ids){
        if (collegeService.removeByIds(Arrays.asList(ids))){
            return RespBean.success("删除成功!");
        }
        return RespBean.error("删除失败！");
    }

    @ApiOperation(value = "查询所有的学院（分页）")
    @GetMapping("/getPageCollege/")
    public RespPageBean getStuLeave(@RequestParam(defaultValue = "1") Integer currentPage ,
                                    @RequestParam(defaultValue = "10")Integer size,
                                    College college){
        return collegeService.getCollegeByPage(currentPage,size,college);
    }

}
